/*******************************************************************************
* Copyright (C) 2019 China Micro Semiconductor Limited Company. All Rights Reserved.
*
* This software is owned and published by:
* CMS LLC, No 2609-10, Taurus Plaza, TaoyuanRoad, NanshanDistrict, Shenzhen, China.
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with CMS
* components. This software is licensed by CMS to be adapted only
* for use in systems utilizing CMS components. CMS shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. CMS is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/

#ifndef __USER_CONTROL_H__
#define __USER_CONTROL_H__
/*****************************************************************************/
/* Include files */
/*****************************************************************************/


/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/

#define ERROR_ADRESS                      0
#define UC_INFO_ADRESS                   1



/*****************************************************************************/
/* Global type definitions ('typedef') */
/*****************************************************************************/

/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/


/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/


/*****************************************************************************/
/* Global type definitions ('typedef') */
/*****************************************************************************/


typedef enum 
{
	TOOL_STOP = 0,	
	TOOL_RUN = 1,
	TOOL_ERROR_STOP = 2,	
	TOOL_POWER_DOWN = 3,
	TOOL_STOPPING = 4,
	TOOL_PRESTOP = 5,
}TOOL_STATE_ENUM;



typedef union
{
	uint32_t Word;
	struct
	{
		uint32_t gLimitAvgCurtOn:1;
	 	uint32_t gLimitPeakCurtOn:1;
	 	uint32_t gCutOcpBack:1;
	 	uint32_t gSOCdisplay:1;
	 	uint32_t gSOCupdate:1;
		uint32_t gStoppingEn:1;
		uint32_t gFirstStart:1;
		uint32_t gCWLevel:1;
		uint32_t gCCWAutoStopEn:1;
		uint32_t gAutoStopMeet:1;
   	 }bits;
	
}CTR_FLAG_UNION;



typedef struct
{
	TOOL_STATE_ENUM ToolState;
	uint32_t motorCircutCnt;
	uint8_t ToolDir;
	uint8_t Tick2ms;
	uint8_t Tick20ms;
	uint8_t buzzerDeal;
	float kDutyCircut2;
	float kDutyCircut1;
	uint16_t LooseDuty;
	uint16_t SocOnCnt;
	ERROR_FLAG_UNION ErrorFlag;
	ERROR_FLAG_UNION WriteErrorFlag;
	ERROR_FLAG_UNION ReadErrorFlag;
	CTR_FLAG_UNION CtrFlag;
	volatile u16 VspAdValue;
	u16 autoStopMsCnt;
}USER_CTR_STR;

extern USER_CTR_STR strUctr;


/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/

void UC_1Ms_Main_Task(void);
void UC_10Ms_Main_Task(void);
void UC_Tool_State_Machine(void);
void UC_Pro_Flag_Manage(void);
void UC_Init_Variable(void);
u8 UC_LED_Error_Flash_Control(void);
void UC_Uarts_State_Machine(void);
void UC_SPN_Key_Deal(void);
void UC_CCW_Auto_Stop_Judge(void);


/**/
uint32_t  UC_Tool_Rpm_Set(uint16_t iTrgAdc);
uint16_t  UC_Tool_Duty_Set(uint16_t iTrgAdc);
void UC_LED_Indication(void);
void UC_Fmc_Write_Data_Set(void);








#endif /* __USER_CONTROL_H__ */


